package com.miaostars.apakey.config;

import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.plugin.java.JavaPlugin;

public class ConfigManager {
    
    private final JavaPlugin plugin;
    private FileConfiguration config;
    
    public ConfigManager(JavaPlugin plugin) {
        this.plugin = plugin;
    }
    
    public void loadConfig() {
        plugin.saveDefaultConfig();
        config = plugin.getConfig();
        
        // Set default values if they don't exist
        config.addDefault("checks.fly.enabled", true);
        config.addDefault("checks.fly.sensitivity", 0.8);
        config.addDefault("checks.fly.max-violations", 10);
        
        config.addDefault("checks.nofall.enabled", true);
        config.addDefault("checks.nofall.sensitivity", 0.7);
        config.addDefault("checks.nofall.max-violations", 8);
        
        config.addDefault("checks.killaura.enabled", true);
        config.addDefault("checks.killaura.max-cps", 15);
        config.addDefault("checks.killaura.max-violations", 12);
        
        config.addDefault("checks.reach.enabled", true);
        config.addDefault("checks.reach.max-distance", 3.5);
        config.addDefault("checks.reach.max-violations", 10);
        
        config.addDefault("checks.inventory.enabled", true);
        config.addDefault("checks.inventory.max-violations", 5);
        
        config.addDefault("checks.highjump.enabled", true);
        config.addDefault("checks.highjump.max-jump-height", 1.25);
        config.addDefault("checks.highjump.max-violations", 8);
        
        // New checks
        config.addDefault("checks.speed.enabled", true);
        config.addDefault("checks.speed.max-violations", 8);
        
        config.addDefault("checks.autoclick.enabled", true);
        config.addDefault("checks.autoclick.max-violations", 5);
        
        config.addDefault("checks.xray.enabled", true);
        config.addDefault("checks.xray.time-window", 60000); // 1 minute in ms
        config.addDefault("checks.xray.max-value", 100);
        
        config.addDefault("alerts.enabled", true);
        config.addDefault("alerts.prefix", "&8[&cApakey&8]");
        config.addDefault("alerts.message", "&c%player% &7failed &c%check% &7(type: &c%type%&7)");
        

        
        config.options().copyDefaults(true);
        plugin.saveConfig();
    }
    
    public void reloadConfig() {
        plugin.reloadConfig();
        config = plugin.getConfig();
    }
    
    public FileConfiguration getConfig() {
        return config;
    }
}